package com.besttone.search.model;

import android.content.Context;
import android.telephony.TelephonyManager;

public class PhoneInfo {  
	  
    private TelephonyManager telephonyManager;  
    /** 
     * 国际移动用户识别码 
     */  
    private String IMSI;
    private Context cxt;  
    public PhoneInfo(Context context) {  
        cxt=context;  
        telephonyManager = (TelephonyManager) context  
                .getSystemService(Context.TELEPHONY_SERVICE);  
    }  
    
    /**
     * 获取IMSI
     */
    public String getIMSI() {
		try {
			IMSI = telephonyManager.getSubscriberId();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return IMSI;
	}

	public void setIMSI(String iMSI) {
		IMSI = iMSI;
	}
    
    /** 
     * 获取电话号码 
     */  
    public String getNativePhoneNumber() {  
        String NativePhoneNumber=null;  
        NativePhoneNumber=telephonyManager.getLine1Number();  
        return NativePhoneNumber;  
    }

	/** 
     * 获取手机服务商信息 
     */  
    public String getProvidersName() {  
        String ProvidersName = "N/A";  
        try{  
        IMSI = telephonyManager.getSubscriberId();  
        // IMSI号前面3位460是国家，紧接着后面2位00 02是中国移动，01是中国联通，03是中国电信。  
        System.out.println(IMSI);  
        if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {  
            ProvidersName = "中国移动";  
        } else if (IMSI.startsWith("46001")) {  
            ProvidersName = "中国联通";  
        } else if (IMSI.startsWith("46003")) {  
            ProvidersName = "中国电信";  
        }  
        }catch(Exception e){  
            e.printStackTrace();  
        }  
        return ProvidersName;  
    }  
      
    public String  getPhoneInfo(){  
         TelephonyManager tm = (TelephonyManager)cxt.getSystemService(Context.TELEPHONY_SERVICE);  
            StringBuilder sb = new StringBuilder();  
  
            sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());  
            sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());  
            sb.append("\nLine1Number = " + tm.getLine1Number());  
            sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());  
            sb.append("\nNetworkOperator = " + tm.getNetworkOperator());  
            sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());  
            sb.append("\nNetworkType = " + tm.getNetworkType());  
            sb.append("\nPhoneType = " + tm.getPhoneType());  
            sb.append("\nSimCountryIso = " + tm.getSimCountryIso());  
            sb.append("\nSimOperator = " + tm.getSimOperator());  
            sb.append("\nSimOperatorName = " + tm.getSimOperatorName());  
            sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());  
            sb.append("\nSimState = " + tm.getSimState());  
            sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());  
            sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());  
           return  sb.toString();  
    }  
    
    private String phoneNo;
	private boolean errorFlag = false;//错误标志位
	private String errorCode = "";//错误代码
	private String errorMsg = "";//错误信息
	public String getPhoneNo() {
		return phoneNo;
	}

	public void setPhoneNo(String phoneNo) {
		this.phoneNo = phoneNo;
	}

	public boolean isErrorFlag() {
		return errorFlag;
	}

	public void setErrorFlag(boolean errorFlag) {
		this.errorFlag = errorFlag;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}
	
	public PhoneInfo() {}
}  